package com.zlc.common.util;

import org.springframework.util.ObjectUtils;

import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class PlatUtils {

    private PlatUtils(){}

    public static final ExecutorService THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(20, 80, 10, TimeUnit.SECONDS, new ArrayBlockingQueue<>(50));

    public static String uuid(){
        return UUID.randomUUID().toString().replaceAll("-","");
    }

    public static String lowerFirst(String name){
        char[] chars = name.toCharArray();
        chars[0] += 32;
        return String.valueOf(chars);
    }

    public static String numberStringNo(int number,int digit){
        String numberStr = String.valueOf(number);
        int length = numberStr.length();
        if(length < digit){
            while(length < digit){
                numberStr = "0".concat(numberStr);
                length = numberStr.length();
            }
        }
        return numberStr;

    }


    public static String numberStringNo(String number,int digit){
        String numberStr = String.valueOf(number);
        int length = numberStr.length();
        if(length < digit){
            while(length < digit){
                numberStr = "0".concat(numberStr);
                length = numberStr.length();
            }
        }
        return numberStr;
    }

    public static boolean hasChange(String oldValue,String newValue){
        if(ObjectUtils.isEmpty(oldValue) && !ObjectUtils.isEmpty(newValue)){
            return true;
        }
        if(!ObjectUtils.isEmpty(oldValue) && ObjectUtils.isEmpty(newValue)){
            return true;
        }
        return !oldValue.equals(newValue);
    }

    public static boolean hasChange(boolean oldValue,boolean newValue){
        if(ObjectUtils.isEmpty(oldValue) && !ObjectUtils.isEmpty(newValue)){
            return true;
        }
        if(!ObjectUtils.isEmpty(oldValue) && ObjectUtils.isEmpty(newValue)){
            return true;
        }
        return oldValue != newValue;
    }

    public static boolean hasChange(Integer oldValue,Integer newValue){
        if(ObjectUtils.isEmpty(oldValue) && !ObjectUtils.isEmpty(newValue)){
            return true;
        }
        if(!ObjectUtils.isEmpty(oldValue) && ObjectUtils.isEmpty(newValue)){
            return true;
        }
        return !oldValue.equals(newValue);
    }

    public static boolean hasChange(Long oldValue,Long newValue){
        if(ObjectUtils.isEmpty(oldValue) && !ObjectUtils.isEmpty(newValue)){
            return true;
        }
        if(!ObjectUtils.isEmpty(oldValue) && ObjectUtils.isEmpty(newValue)){
            return true;
        }
        return !oldValue.equals(newValue);
    }

    public static boolean hasChange(Double oldValue,Double newValue){
        if(ObjectUtils.isEmpty(oldValue) && !ObjectUtils.isEmpty(newValue)){
            return true;
        }
        if(!ObjectUtils.isEmpty(oldValue) && ObjectUtils.isEmpty(newValue)){
            return true;
        }
        return !oldValue.equals(newValue);
    }

    public static boolean hasChange(Float oldValue,Float newValue){
        if(ObjectUtils.isEmpty(oldValue) && !ObjectUtils.isEmpty(newValue)){
            return true;
        }
        if(!ObjectUtils.isEmpty(oldValue) && ObjectUtils.isEmpty(newValue)){
            return true;
        }
        return !oldValue.equals(newValue);
    }

    public static boolean hasChange(Character oldValue,Character newValue){
        if(ObjectUtils.isEmpty(oldValue) && !ObjectUtils.isEmpty(newValue)){
            return true;
        }
        if(!ObjectUtils.isEmpty(oldValue) && ObjectUtils.isEmpty(newValue)){
            return true;
        }
        return !oldValue.equals(newValue);
    }
}
